/**
 * 
 * Created on 28 apr. 2011 @ 16:25:09 by Laurens Andriessen
 */

package combat.dudes;

import combat.dudes.protocol.data.DoublePoint;
import combat.dudes.protocol.types.PhysicalObjectType;
import combat.dudes.protocol.types.ProjectileType;
import combat.dudes.protocol.types.SensorSystemType;
import combat.dudes.protocol.types.VehicleType;
import combat.dudes.protocol.types.WeaponSystemType;


/**
 * The global configurations for both server and client.
 * @author Laurens Andriessen
 * @author Jesper Keijzer
 */
public final class DudesConfig {

	// Debug mode
	public static Boolean debugMode = false;

	// Cajo framework variables
	// public static String serverAddr = "145.81.0.135";
	public static String serverAddr = ""; // Server name
	public static int serverPort = 28000; // Server port
	public static String serverUrl = "//" + serverAddr + ":" + serverPort + "/"; // Full url

	/**
	 * Set the full server url in a single function call
	 * @param server For example "localhost" or "combat.inholland.nl"
	 */
	public static void setServerUrl(String server) {
		setServerAddr(server);
		serverUrl = "//" + server + ":" + serverPort + "/";
	}
	public static String getServerAddr() {
		return serverAddr;
	}
	public static void setServerAddr(String server) {
		serverAddr = server;
	}


	/**
	 * Shared static variables
	 * @author Jesper Keijzer
	 */
	public static class SharedVars {
		// MaxSpeedsVehicle
		public static final double unknownVehicleSpeedMax = 60;
		public static final double convoySpeedMax = 60;
		public static final double frigateSpeedMax = 50;
		public static final double submarineSpeedMax = 30;

		// MaxSpeedsProjectile
		public static final double unknownProjectileSpeedMax = 220;
		public static final double missile_unguidedSpeedMax = 220;
		public static final double missile_guidedSpeedMax = 190;
		public static final double torpedoSpeedMax = 90;

		// MaxProjectileDistance
		public static final double unknownProjectileDistanceMax = 25;
		public static final double missile_unguidedDistanceMax = 25;
		public static final double missile_guidedDistanceMax = 35;
		public static final double torpedoDistanceMax = 10;

		// MaxSensorDistance
		public static final int unknownSensorDistanceMax = 45;
		public static final int sightDistanceMax = 45;
		public static final int radarDistanceMax = 40;
		public static final int sonarDistanceMax = 35;

		// DefaultWeaponAmmo
		public static final int unknownWeaponAmmo = 25;
		public static final int unguided_missilelauncherAmmo = 25;
		public static final int guided_missilelauncherAmmo = 10;
		public static final int torpedolauncherAmmo = 15;
		public static final int goalkeeperAmmo = 4;

		// MaxVehicleFuel
		public static final double unknownVehicleFuel = 600.0;
		public static final double convoyFuel = 400.0;
		public static final double frigateFuel = 500.0;
		public static final double submarineFuel = 320.0;

		// MaxTurnAngle
		public static final double unknownVehicleMaxAngle = 4.0;
		public static final double convoyMaxAngle = 2.5;
		public static final double frigateMaxAngle = 4.0;
		public static final double submarineMaxAngle = 2.5;

		// MapSize
		public static final DoublePoint mapSize = new DoublePoint(150, 150);

		// RefreshTime (TO HIGH VALUE MAY CAUSE WRONG EVENTS/MOVES)
		public static final int refreshTime = 8;

		// Hit range (MIND REFRESH RATE AND SIMSPEED)
		public static final double projectileHitRange = 0.6;
		public static final double vehicleHitRange = 0.3;
		public static final double unknownHitRange = 0.6;

		// Arrive range (MIND REFRESH TIME AND SIMSPEED)
		public static final double ArriveRange = 0.05;

		/**
		 * Returns the default maximum speed of a VehicleType
		 * @author Jesper Keijzer
		 * @return double
		 */
		public static double getMaxSpeed(VehicleType type) {
			switch(type) {
				case UNKNOWN:
					return unknownVehicleSpeedMax;
				case CONVOY:
					return convoySpeedMax;
				case FRIGATE:
					return frigateSpeedMax;
				case SUBMARINE:
					return submarineSpeedMax;
				default:
					return unknownVehicleSpeedMax;
			}
		}

		/**
		 * Returns the default maximum speed of a ProjectileType
		 * @author Jesper Keijzer
		 * @return double
		 */
		public static double getMaxSpeed(ProjectileType type) {
			switch(type) {
				case UNKNOWN:
					return unknownProjectileSpeedMax;
				case MISSILE_UNGUIDED:
					return missile_unguidedSpeedMax;
				case MISSILE_GUIDED:
					return missile_guidedSpeedMax;
				case TORPEDO:
					return torpedoSpeedMax;
				default:
					return unknownProjectileSpeedMax;
			}
		}

		/**
		 * Returns the default maximum distance of a ProjectileType
		 * @author Jesper Keijzer
		 * @return double
		 */
		public static double getMaxDistance(ProjectileType type) {
			switch(type) {
				case UNKNOWN:
					return unknownProjectileDistanceMax;
				case MISSILE_UNGUIDED:
					return missile_unguidedDistanceMax;
				case MISSILE_GUIDED:
					return missile_guidedDistanceMax;
				case TORPEDO:
					return torpedoDistanceMax;
				default:
					return unknownProjectileDistanceMax;
			}
		}

		/**
		 * Returns the default maximum distance of a SensorSystemType
		 * @author Jesper Keijzer
		 * @return double
		 */
		public static int getMaxDistance(SensorSystemType type) {
			switch(type) {
				case UNKNOWN:
					return unknownSensorDistanceMax;
				case RADAR:
					return radarDistanceMax;
				case SIGHT:
					return sightDistanceMax;
				case SONAR:
					return sonarDistanceMax;
				default:
					return unknownSensorDistanceMax;
			}
		}

		/**
		 * Returns the default ammo of a WeaponSystemType
		 * @author Jesper Keijzer
		 * @return double
		 */
		public static int getDefaultAmmo(WeaponSystemType type) {
			switch(type) {
				case UNKNOWN:
					return unknownWeaponAmmo;
				case GOALKEEPER:
					return goalkeeperAmmo;
				case TORPEDOLAUNCHER:
					return torpedolauncherAmmo;
				case GUIDED_MISSILELAUNCHER:
					return guided_missilelauncherAmmo;
				case UNGUIDED_MISSILELAUNCHER:
					return unguided_missilelauncherAmmo;
				default:
					return unknownWeaponAmmo;
			}
		}

		/**
		 * Returns the max fuel of a VehicleType
		 * @author Jesper Keijzer
		 * @return double
		 */
		public static double getMaxFuel(VehicleType type) {
			switch(type) {
				case UNKNOWN:
					return unknownVehicleFuel;
				case CONVOY:
					return convoyFuel;
				case FRIGATE:
					return frigateFuel;
				case SUBMARINE:
					return submarineFuel;
				default:
					return unknownVehicleFuel;
			}
		}

		/**
		 * Returns the max turn angle per second of a vehicle type
		 * @author Jesper Keijzer
		 * @return double
		 */
		public static double getMaxTurnAngle(VehicleType type) {
			switch(type) {
				case UNKNOWN:
					return unknownVehicleMaxAngle;
				case CONVOY:
					return convoyMaxAngle;
				case FRIGATE:
					return frigateMaxAngle;
				case SUBMARINE:
					return submarineMaxAngle;
				default:
					return unknownVehicleMaxAngle;
			}
		}

		/**
		 * Returns the default mapSize
		 * @author Jesper Keijzer
		 * @return doublePoint
		 */
		public static DoublePoint getMapSize() {
			return mapSize;
		}

		/**
		 * Returns the refreshTime in ms
		 * @author Jesper Keijzer
		 * @return int
		 */
		public static int getRefreshTime() {
			return refreshTime;
		}

		/**
		 * Returns the hitRange in coordinates-distance
		 * @author Jesper Keijzer
		 * @return double
		 */
		public static double getHitRange(PhysicalObjectType type) {
			switch(type) {
				case PROJECTILE:
					return projectileHitRange;
				case VEHICLE:
					return vehicleHitRange;
				default:
					return unknownHitRange;
			}
		}
		/**
		 * Returns the arriveRange in coordinates-distance
		 * @author Jesper Keijzer
		 * @return double
		 */
		public static double getArriveRange() {
			return ArriveRange;
		}
	}
}
